/**
 * @Author: Sagan
 * @Date: 2020/09/19 13:34
 */
package function

import (
	"net"
)

func IP(ip string) bool {
	return nil != net.ParseIP(ip)
}

func IPv4(ip string) bool {
	if nil == net.ParseIP(ip) {
		return false
	}

	for i := 0; i < len(ip); i++ {
		if '.' == ip[i] {
			return true
		}
	}
	return false
}

func IPv6(ip string) bool {
	if nil == net.ParseIP(ip) {
		return false
	}

	for i := 0; i < len(ip); i++ {
		if ':' == ip[i] {
			return true
		}
	}
	return false
}
